package com.haiheng.voiceandbook.view;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;

import com.haiheng.voiceandbook.MyApplication;
import com.haiheng.voiceandbook.utils.Density;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * 此webView为了解决适配问题、在使用适配方案的项目中使用webView会density 复原，原因是由于 WebView 初始化的时候会还原 density 的值导致适配失效
 * Created by Administrator on 2018/11/10.
 */

public class BookWebView extends WebView {


    public BookWebView(@NonNull Context context) {
        super(context);
        init((Activity) context);

    }
    public BookWebView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init((Activity) context);
    }




    public BookWebView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init((Activity) context);
    }

    public BookWebView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init((Activity) context);
    }
    private void init(Activity context) {
        Density.setDensity(MyApplication.Companion.getInstance(),context);
    }
    @Override
    public void setOverScrollMode(int mode) {
        super.setOverScrollMode(mode);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    }
}

